package com.daiyang.blog.controller;

import com.daiyang.blog.common.result.Result;
import com.daiyang.blog.pojo.AddBlogInfoParam;
import com.daiyang.blog.service.DTO.BlogInfoResponse;
import com.daiyang.blog.service.BlogService;

import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/blog")
@RestController
public class BlogController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse>getList() {
        return blogService.getList();

    }

    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId) {
        log.info("getBlogDetail BlogId:{}", blogId);
        return blogService.getBlogDetail(blogId);
    }
    @RequestMapping("/add")
    public Result<Boolean> addBlog(@Validated @RequestBody AddBlogInfoParam
                                           addBlogInfoParam){
        log.info("addBlog 接收参数: "+ addBlogInfoParam);
        return Result.resultSuccess(blogService.addBlog(addBlogInfoParam));
    }


}
